<template>
  <section class="todoapp">
    <!-- 除了驼峰, 还可以使用-转换链接 -->
    <TodoHeader @chuan="chuan" :list="list"></TodoHeader>
    <TodoMain @shan="shan" :list="shaixuan"></TodoMain>
    <TodoFooter @shai="shai" @ :list="list"></TodoFooter>
  </section>
</template>

<script>
// 1.0 样式引入
import "./styles/base.css";
import "./styles/index.css";

import TodoHeader from "./components/t-h.vue";
import TodoMain from "./components/t-m.vue";
import TodoFooter from "./components/t-f.vue";

export default {
  components: {
    TodoHeader,
    TodoMain,
    TodoFooter,
  },
  data() {
    return {
      isAl: "all",
      list: [
        { id: 100, name: "吃饭", isDone: true },
        { id: 201, name: "睡觉", isDone: false },
        { id: 103, name: "打豆豆", isDone: true },
      ],
    };
  },
  methods: {
    chuan(neirong) {
      let id =
        this.list.length == 0
          ? 100
          : this.list.findIndex((item) => item.id == id);
      this.list.push({
        id: id,
        name: neirong,
        isDone: false,
      });
    },
    shan(id) {
      let index = this.list.findIndex((item) => item.id == id);
      this.list.splice(index, 1);
    },
    shai(isAl) {
      this.isAl = isAl;
    },
  },
  computed: {
    shaixuan() {
      console.log(this.list.filter((item) => item.isDone == true));
      if (this.isAl == "yes") {
        return this.list.filter((item) => item.isDone);
      } else if (this.isAl == "no") {
        return this.list.filter((item) => !item.isDone);
      } else {
        return this.list;
      }
    },
  },
};
</script>